package com.keyancompany.zhongbaopingtai.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.keyancompany.zhongbaopingtai.R;
import com.keyancompany.zhongbaopingtai.model.Label;

import java.util.List;

/**
 * Created by firefox on 2016/6/16.
 */
public class MyLabelAdapter extends RecyclerView.Adapter<MyLabelAdapter.ViewHolder> {
    private List<Label> list;
    public MyLabelAdapter( List<Label> list ) {
        this.list = list;
    }
    //创建新View，被LayoutManager所调用
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
        View view = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.item_label,viewGroup,false);
        ViewHolder vh = new ViewHolder(view);
        return vh;
    }
    //将数据与界面进行绑定的操作
    @Override
    public void onBindViewHolder(ViewHolder viewHolder, int position) {
        viewHolder.name.setText("标签名称:"+list.get(position).getLabelName());
        viewHolder.color.setText("标签颜色:"+list.get(position).getLabelcolor());
    }
    //获取数据的数量
    @Override
    public int getItemCount() {     return list.size();}
    //自定义的ViewHolder，持有每个Item的的所有界面元素
    public static class ViewHolder extends RecyclerView.ViewHolder {
        TextView name;
        TextView color;
        public ViewHolder(View view){
            super(view);
            name = (TextView) view.findViewById(R.id.label_name);
            color = (TextView) view.findViewById(R.id.label_color);
        }
    }
}